﻿using SCG.General;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TTEngine
{
    public class RoughRoom : Room
    {
        //constructor
        public RoughRoom()
            : base()
        {
            UseConnectorPoints = true;

            //start with large empty area
            Matrix = new CharMatrix(100, 100);
            Matrix.Fill(Globals.TERRAIN_WALL);

            //carve out from the center
            int length = Globals.RandomIntFromTo(10, 100);
            int repeat = Globals.RandomIntFromTo(1, 6);
            Carve(50, 50, length, repeat);

            //crop the result
            Matrix = Matrix.Crop(Globals.TERRAIN_WALL);

            //calculate connectors
            for(int x = 0; x < Width; x++)
                if (Matrix.Get(x, Height - 1) != Globals.TERRAIN_WALL)
                {
                    StartConnector = x;
                    break;
                }
            for (int times = 0; times < 6; times++)
            {
                int x = Globals.RandomIntFromTo(0, Width - 1);
                if (Matrix.Get(x, Height - 1) != Globals.TERRAIN_WALL)
                {
                    StartConnector = x;
                    break;
                }
            }
            for(int x = 0; x < Width; x++)
                if (Matrix.Get(x, 0) != Globals.TERRAIN_WALL)
                {
                    EndConnector = x;
                    break;
                }
            for (int times = 0; times < 6; times++)
            {
                int x = Globals.RandomIntFromTo(0, Width - 1);
                if (Matrix.Get(x, 0) != Globals.TERRAIN_WALL)
                {
                    EndConnector = x;
                    break;
                }
            }
        }

        //clone
        public override Room Clone()
        {
            return new RoughRoom();
        }
    }
}
